# -------------------------------------------------------------------------------------------------------------
# Main CMakeLists.txt for fit-mi-run project.
# -------------------------------------------------------------------------------------------------------------
cmake_minimum_required(VERSION 2.8)

# -------------------------------------------------------------------------------------------------------------
# <project>
# -------------------------------------------------------------------------------------------------------------
project(fit-mi-run)
# -------------------------------------------------------------------------------------------------------------
# </project>
# -------------------------------------------------------------------------------------------------------------

# -------------------------------------------------------------------------------------------------------------
# <predefined internal variables for options>
# -------------------------------------------------------------------------------------------------------------

# -------------------------------------------------------------------------------------------------------------
# </predefined internal variables for options>
# -------------------------------------------------------------------------------------------------------------

# -------------------------------------------------------------------------------------------------------------
# <options>
# -------------------------------------------------------------------------------------------------------------
option(BUILD_X64        "Whether to build in 64-bits mode (-m64)." OFF)


set(EXECUTABLE_OUTPUT_PATH "${PROJECT_SOURCE_DIR}/../bin")


if ("${CMAKE_BUILD_TYPE}" STREQUAL "")
    message(STATUS "Build type not specified, using: Release.")
endif ()
set(CMAKE_BUILD_TYPE "release" CACHE STRING "Build type.")
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "debug" "release")

set(INSTALL_PLATFORM_DIR "" CACHE STRING 
                         "Installation subdirectory name for libraries and executables for current platform.")
# -------------------------------------------------------------------------------------------------------------
# </options>
# -------------------------------------------------------------------------------------------------------------

# -------------------------------------------------------------------------------------------------------------
# <process options>
# -------------------------------------------------------------------------------------------------------------

# -------------------------------------------------------------------------------------------------------------
# </process options>
# -------------------------------------------------------------------------------------------------------------

# -------------------------------------------------------------------------------------------------------------
# <customize CMAKE settings>
# -------------------------------------------------------------------------------------------------------------
if (NOT MSVC)
    if (UNIX)
        if (BUILD_X64)
            set(COMPILE_FLAGS "-m64")
            set(LINK_FLAGS    "-m64")
        else ()
            set(COMPILE_FLAGS "-m32")
            set(LINK_FLAGS    "-m32")
        endif ()
 
        if ("${CMAKE_BUILD_TYPE}" STREQUAL "release")
            set(LINK_FLAGS "-s ${LINK_FLAGS}")
        endif()
    endif ()
    set(CMAKE_CXX_FLAGS                 "-Wall -fno-rtti -std=c++11 ${COMPILE_FLAGS} ${CMAKE_CXX_FLAGS}")
    set(CMAKE_C_FLAGS                   "-Wall ${COMPILE_FLAGS} ${CMAKE_C_FLAGS}")
    set(CMAKE_EXE_LINKER_FLAGS          "${LINK_FLAGS} ${CMAKE_EXE_LINKER_FLAGS}")
    set(CMAKE_MODULE_LINKER_FLAGS       "${LINK_FLAGS} ${CMAKE_MODULE_LINKER_FLAGS}")
    set(CMAKE_SHARED_LINKER_FLAGS       "${LINK_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS}")
elseif (MSVC)
    set(CMAKE_CXX_FLAGS                 "/W3 ${CMAKE_CXX_FLAGS}")
    set(CMAKE_C_FLAGS                   "/W3 ${CMAKE_C_FLAGS}")
    add_definitions(-D_CRT_SECURE_NO_WARNINGS)
endif ()

if ("${CMAKE_BUILD_TYPE}" STREQUAL "release")
    add_definitions(-DNDEBUG)
endif()
# -------------------------------------------------------------------------------------------------------------
# </customize CMAKE settings>
# -------------------------------------------------------------------------------------------------------------

# -------------------------------------------------------------------------------------------------------------
# <global includes>
# -------------------------------------------------------------------------------------------------------------
include_directories(
    ${CMAKE_SOURCE_DIR}
    ${CMAKE_SOURCE_DIR}/../include
)

# -------------------------------------------------------------------------------------------------------------
# </global includes>
# -------------------------------------------------------------------------------------------------------------

# -------------------------------------------------------------------------------------------------------------
# <modules> (libraries)
# -------------------------------------------------------------------------------------------------------------



# -------------------------------------------------------------------------------------------------------------
# </modules>
# -------------------------------------------------------------------------------------------------------------

# -------------------------------------------------------------------------------------------------------------
# <binaries>
# -------------------------------------------------------------------------------------------------------------

add_subdirectory(compiler)
add_subdirectory(vm)

# -------------------------------------------------------------------------------------------------------------
# </binaries>
# -------------------------------------------------------------------------------------------------------------

# -------------------------------------------------------------------------------------------------------------
# <tests>
# -------------------------------------------------------------------------------------------------------------

#add_subdirectory(tests)

# -------------------------------------------------------------------------------------------------------------
# </tests>
# -------------------------------------------------------------------------------------------------------------

